<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	领奖记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['types']=array(
	'1'=>'连续签到奖励',
	'2'=>'累计签到奖励'
);
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	//奖品名称
	$return['params']=array();
	if(!empty($_RQ['rid'])){
		$params['rid']=intval($_RQ['rid']);
		$return['params']['rid']=$_RQ['rid'];
	}
	$orderby='id desc';
	$list=pdo_getslice('core_reward_log',$params,array($pindex,$psize),$total,array(),'',$orderby);
	if($list){
		foreach($list as &$item){
			$item['member']=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('nickname','avatar'));
			$item['reward']=pdo_get('core_reward',array('id'=>$item['rid'],'uniacid'=>$_SESSION['uniacid']),array('type','title'));
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'领奖记录'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'member.nickname','title'=>'会员昵称','type'=>'string'),
			array('name'=>'member.avatar','title'=>'会员头像','type'=>'image'),
			array('name'=>'reward.type','title'=>'奖品类型','type'=>'radio','options'=>'types'),
			array('name'=>'reward.title','title'=>'奖品名称','type'=>'string'),
			array('name'=>'createtime','title'=>'领奖时间','type'=>'time'),
		)),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	//删除奖品
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_reward_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('core_reward_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}